package com.woldier.zuul.filter;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;

import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import javax.servlet.http.HttpServletRequest;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;
@Component
@Slf4j
public class AccessFilter extends BaseFilter{
    /**
     * 指定filter类型
     * @return
     */
    @Override
    public String filterType() {
        return PRE_TYPE;
    }

    /**
     * 设置执行顺序 要在 PRE_DECORATION之后执行
     * @return
     */
    @Override
    public int filterOrder() {
        return FilterConstants.PRE_DECORATION_FILTER_ORDER + 1;
    }

    /**
     * 是否开启该filter
     * @return
     */

    @Override
    public boolean shouldFilter() {
        return true;
    }

    /**
     * 执行逻辑
     * @return
     * @throws ZuulException
     */
    @Override
    public Object run() throws ZuulException {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        String s = request.getRequestURI();
        log.info(s);
        //TODO  进行访问控制 若不允许通过则调用BaseFilter的errorResponse方法

        //TODO 判断是否是上传的uri 若为上传的uri在ThreadLocal中保存updateTime
        return null;
    }
}
